﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Livraria._Default" %>
<%@ Import Namespace ="System.Data" %>
<%@ Import Namespace ="System.Data.SqlClient" %>





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<script language="c#" runat="Server">

    SqlConnection conn;
    public void Page_Load (Object Src, EventArgs E)
    {
       string strConn = @"Data Source=localhost\sqlexpress;Initial Catalog=Linguagem_Web;Integrated Security=True";
       conn = new SqlConnection(strConn);
       
       if(!IsPostBack)
       {
         BindDG();
       }
    }
       private void BindDG()
       {
           string tabela = "Produtos";
         string sqlQuery = "select * from Produtos";
         SqlDataAdapter command = new SqlDataAdapter(sqlQuery ,conn);
         
         DataSet ds = new DataSet();
         command.Fill(ds,"Produtos");
         dglivraria.DataSource = ds.Tables["Produtos"];
         dglivraria.DataBind();         
       }


</script>
<head runat="server">
    <title>Livraria</title>
</head>
<body>
    <form id="livraria" runat="server">
        <h3> Livraria do Mario</h3>
        <span id="message" enableviewstate="false" runat="server"/>
        <asp:DataGrid ID="dglivraria" width="400" ShowFooter="false" runat="server">
        <Columns>
        <asp:EditCommandColumn EditText="Editar" UpdateText="Atualizar" CancelText="Cancelar"/>
        </Columns>
        </asp:DataGrid>      
    </form>
</body>
</html>
